.netCHARTING v5.2 Documentation Send comments on this topic.
Calendar Patterns
Getting Started > General Tutorials > Calendar Patterns

Glossary Item Box

Introduction

A CalendarPattern class specifies a pattern such as specific days in a week, months in a year etc. You can specify a time unit of any other time unit to form the pattern. For example: weeks of a year, seconds of a minute, days of a year, even milliseconds of a year.


Uses

Calendar patterns can be used with axis markers to highlight parts of a time scale axis and with Series.Trim to trim away elements with time values that land within the calendar pattern. They can also be used to specify a sequence of scale breaks on a time based axis.


Usage

The pattern is represented by an array of boolean values, each boolean value represents the specified PatternUnit and the whole array represents the specified CalendarUnit.

The CalendarPattern.PatternFromString method can be used to quickly create patterns using simple string of zeros (0) and ones (1). A week pattern would look like this: "0000000". A zero for each day of the week starting with saturday and ending with sunday. A pattern that flags the weekend (saturday and sunday) would look like this: "1000001".

 

Example:

[C#]

CalendarPattern myCalendarPattern = new CalendarPattern();
myCalendarPattern.CalendarUnit = TimeInterval.Week;

myCalendarPattern.PatternUnit = TimeInterval.Day;

myCalendarPattern.Pattern = CalendarPattern.FromString("1000001");

[Visual Basic]

Dim myCalendarPattern As CalendarPattern = new CalendarPattern()
myCalendarPattern.CalendarUnit = TimeInterval.Week

myCalendarPattern.PatternUnit = TimeInterval.Day

myCalendarPattern.Pattern = CalendarPattern.FromString("1000001")

In a pattern the __Unit properties refer to a single value (PatternUnit) and the whole pattern (CalendarUnit) like so:

"1000001" <-- CalendarUnit (Week)
 ^
PatternUnit of CalendarUnit (Sunday)


The above calendar pattern will flag each saturday and sunday in a given, time span.

If all the values are not provided, the pattern will assume false for the missing values. So if we used "100" for the above pattern, it would be the same as "1000000"

 

Calendar Patterns require a time axis scale.
When a calendar pattern is used in an axis marker, the axis marker must reside on an axis with a time scale. For more information see Elements & Axis scales.

 

CalendarPattern Shortcuts

There are two calendarPattern static properties that allow you to initialize an instance of the calendar pattern object quickly. The properties are Weekends and Weekdays.

The following code instantiates a weekend calendarPattern and is the equivalent of the four lines of code shown above.

[C#]

CalendarPattern myCalendarPattern = CalendarPattern.Weekends;

[Visual Basic]

CalendarPattern myCalendarPattern = CalendarPattern.Weekends

Adjustment Unit

Calendar patterns are drawn on the axis at exact time instances like the start of the day, end of the day, etc. If you use a pattern like the above and your data shows days as columns, the actual x axis time of those columns may also be the start of the day. This results in the columns being centered on the edge of the pattern. The expected behavior would be that the pattern edges fall between the day columns. To remedy this issue you may use the AdjustmentUnit. This will allow you to adjust the calendar pattern to show correctly on the axis. If your columns represent hours the correct adjustment unit would be TimeInterval.Hour.

 

Sample: calendarPattern.aspx
©2008. All Rights Reserved.